<?php

require_once( '../conf/conf.inc' );
require_once( PATH_FRAME.'/etwork.php' );

$etw = new etwork;
$etw->parseURL('hito', 1);

if (! isset($etw->pathParameters[0]) ) {
    
    $etw->setTemplate('hito', false, TRUE, 1);

    $etw->setPankuzu(array(
        array('dir'=>'', 'config'=>'index')
    ));
    $etw->setTitle(array('hito','list'));

    $loader = new modelLoader;
    $loader->model = 'hito';
    $loader->order = @$etw->EX_GET['r'] ? $etw->EX_GET['r'] : '_update_date';
    $loader->alike = @$etw->EX_GET['s'];
    $loader->offset = @$etw->EX_GET['p'];
    $loader->returning = 'list';
    $etw->addLoader($loader);

    if (! $etw->isCached() ) {
        $etw->loadData();
    }

} else if (isNumber($etw->pathParameters[0])) {

    $etw->setTemplate( 'hito', 0, 0, $etw->pathParameters[0] );
    $etw->addClearTemplate( null, 'hito|solo'.$etw->pathParameters[0]);

    $etw->setPankuzu(array(
        array('dir'=>'', 'config'=>'index'),
        array('dir'=>'hito', 'config'=>array('hito','list'))
    ));
    $etw->setTitle(null, array('solo'=>'name'));

    $etw->noCaching = true;

    $etw->jumpTo = URL_EDIT .'hito';

    $loader = new modelLoader;
    $loader->model = 'hito';
    $loader->solo = $etw->pathParameters[0];
    $loader->targetId = 'hito_id';
    $loader->returning = 'solo';
    $loader->isEdit = TRUE;
    $loader->mapperParameters = array(
        'editor_id' => $etw->getUserId()
    );
    $etw->addLoader($loader);

    //カテゴリ
    if ($etw->pathParameters[0] && !$etw->EX_POST) {
        
        $loader = new modelLoader;
        $loader->model = 'category';
        $loader->targetCustomFunction = 'updatePostCategory';
        $loader->targetChoiceFunction = 'findParameterByPost';
        $loader->targetId = 'hito_id';
        $loader->returning = 'list';
        $loader->isEdit = true;
        $loader->solo = $etw->pathParameters[0];
        $loader->formParameters = array('_category');
        $etw->addLoader($loader);
    }

    //カテゴリフォーム
    $loader = new modelLoader;
    $loader->model = 'category';
    $loader->targetId = 'slug';
    $loader->solo = 'hito';
    $loader->targetChoiceFunction = 'findByPost';
    $loader->returning = 'listform';
    $etw->addLoader($loader);

    if (! $etw->isCached() ) {
        $etw->loadData();
    }

}

$etw->showFinal();


